use std::sync::Arc;
use tokio::sync::Mutex;

mod api;
use api::lzizyapi::{get_channel_video_data, search, Lzizy};

use crate::api::lzizyapi::get_target_video_data;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    let cache_config = tauri_plugin_cache::CacheConfig {
        cache_dir: Some("my_app_cache".into()),                                  // Custom subdirectory within app's cache directory
        cache_file_name: Some("cache_data.json".into()),                         // Custom cache file name
        cleanup_interval: Some(360),                                             // Clean expired items every 120 seconds
        default_compression: Some(true),                                         // Enable compression by default
        compression_level: Some(7),                                              // Higher compression level (0-9, where 9 is max)
        compression_threshold: Some(4096),                                       // Only compress items larger than 4KB
        compression_method: Some(tauri_plugin_cache::CompressionMethod::Lzma2),  // Default compression algorithm
    };

    tauri::Builder::default()
        .plugin(tauri_plugin_cache::init_with_config(cache_config))
        .plugin(tauri_plugin_opener::init())
        // 创建Lzizy实例对象并将其通过.manage命令添加到Tauri的状态管理器中
        .manage(Arc::new(Mutex::new(Lzizy::new())))
        .invoke_handler(tauri::generate_handler![
            get_channel_video_data,
            search,
            get_target_video_data
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
